// src/store/$t.mixin.js

export function createGlobalMixin(store) {
  // 确保 store 存在
  if (!store) {
    console.error('createGlobalMixin: store is required')
    return {}
  }

  const $tStoreKey = store.state ? Object.keys(store.state) : []

  return {
    beforeCreate() {
      if (!this.$t) {
        this.$t = {}
      }
      this.$t.vuex = (name, value) => {
        this.$store.commit('$tStore', { name, value })
      }
    },
    computed: {
      ...$tStoreKey.reduce((computed, key) => {
        computed[key] = function () {
          return this.$store.state[key]
        }
        return computed
      }, {})
    }
  }
}